/**
 * Created by forcht on 2018/4/27.
 */
public class Solution {
    public int candy(int[] ratings) {
        int[] a=new int[ratings.length];
        for(int i=1;i<ratings.length;i++){
            if (ratings[i]>ratings[i-1])a[i]=a[i-1]+1;
        }
        for(int i=ratings.length-2;i>=0;i--){
            if(ratings[i]>ratings[i+1]&&a[i]<=a[i+1])a[i]=a[i+1]+1;
        }
        int sum=0;
        for(int i=0;i<ratings.length;i++){
            sum+=a[i];
        }
        return sum+ratings.length;
    }
}
